//
//  HNSH_CreateChatGroupCell.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/2/17.
//

#import "HNSH_CreateChatGroupCell.h"

@interface HNSH_CreateChatGroupCell ()
/** */
@property (nonatomic, strong)UIButton * selBtn;
/** */
@property (nonatomic, strong)UIImageView * imgView;
/** */
@property (nonatomic, strong)UILabel * nameLabel;
/** */
@property (nonatomic, strong)UIView * segView;
@end

@implementation HNSH_CreateChatGroupCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = [UIColor appWhiteLabelColor];
        self.backgroundColor = [UIColor appWhiteLabelColor];
        [self configUI];
    }
    return self;
}

- (void)configUI {
    [self addAllViews];
    [self addAllLayout];
}

//MARK: Myself Methods
- (void)addAllViews{
    [self.contentView addSubview:self.imgView];
    [self.contentView addSubview:self.nameLabel];
    [self.contentView addSubview:self.selBtn];
    [self.contentView addSubview:self.segView];
}

- (void)addAllLayout{
    [self.selBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(24);
        make.left.mas_equalTo(16);
        make.centerY.mas_equalTo(self.contentView);
    }];
    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(40);
        make.left.mas_equalTo(self.selBtn.mas_right).offset(12);
        make.centerY.mas_equalTo(self.contentView);
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.imgView.mas_right).offset(12);
        make.right.mas_equalTo(-60);
        make.top.height.mas_equalTo(self.contentView);
    }];
    [self.segView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.nameLabel);
        make.right.mas_equalTo(0);
        make.height.mas_equalTo(0.5);
        make.bottom.mas_equalTo(0);
    }];
}

//MARK: Setter Methods
- (void)setModel:(HNSH_ChatFriendModel *)model {
    _model = model;
    HNSH_ChatFriendUserModel * user = model.user;
    [self.imgView sd_setImageWithURL:[NSURL URLWithString:user.portrait] placeholderImage:[UIImage imageNamed:@"base_user_header_icon"]];
    self.nameLabel.text = user.display_name.length ? user.display_name : user.name;
    self.selBtn.selected = model.selected;
}

//MARK: Getter Methods
- (UIImageView *)imgView{
    if (!_imgView) {
        _imgView = [UIImageView new];
        _imgView.layer.cornerRadius = 8;
        _imgView.layer.masksToBounds = YES;
        _imgView.image = [UIImage imageNamed:@"base_user_header_icon"];
    }
    return _imgView;
}

- (UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [UILabel new];
        _nameLabel.font = [UIFont systemFontOfSize:16];
        _nameLabel.textColor = [UIColor appBlack333LabelColor];
    }
    return _nameLabel;
}

- (UIButton *)selBtn{
    if (!_selBtn) {
        _selBtn = [UIButton new];
        [_selBtn setImage:[UIImage imageNamed:@"base_select_off"] forState:UIControlStateNormal];
        [_selBtn setImage:[UIImage imageNamed:@"base_select_on"] forState:UIControlStateSelected];
        _selBtn.userInteractionEnabled = NO;
    }
    return _selBtn;
}

- (UIView *)segView{
    if (!_segView) {
        _segView = [UIView new];
        _segView.backgroundColor = [UIColor colorWithHexString:@"#F5F5F5"];
    }
    return _segView;
}

@end
